package statisticalCalculatorTests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import statisticalCalculator.ClassicalProbability;

public class ClassicalProbabilityTests {
	ClassicalProbability classicProb;
	private final double delta = 0.0001;

	@Before
	public void setUp() {
		classicProb = new ClassicalProbability(2.0, 20.0);
	}

	@After
	public void tearDown() {
		classicProb = null;
	}

	@Test
	public void ClassicalProbabilityIsNotNull() {
		assertNotNull(classicProb);
	}

	@Test
	public void canSetNumberOfEventsAndNumberOfPossibleOutcomes() {

		assertNotNull(classicProb);
	}

	@Test
	public void canSetNumberOfEvents() {

		assertEquals(2.0, classicProb.getNumOfEvents(), delta);
	}

	@Test
	public void canSetNumberOfPossibleOutcomes() {

		assertEquals(20.0, classicProb.getNumOfPossibleOutcomes(), delta);
	}

	@Test
	public void canCalculateProbabiltyWhenNumofoutcomesequals10andNumOfEventsequals20() {

		double expected = 0.1;
		assertEquals(expected, classicProb.calculateClassicalProbabilty(),
				delta);
	}

	@Test
	public void calculateProbabiltyThatEventDoesnotOccur() {
		double expected = 0.9;
		assertEquals(expected, classicProb.calcProbabiltyOfOppositeEvent());
	}

	@Test(expected = IllegalArgumentException.class)
	public void ThrowsExceptionWhenNumOfEventsOccuredIsNegative()
			throws Exception {
		new ClassicalProbability(-1, 10);
	}

	@Test(expected = IllegalArgumentException.class)
	public void ThrowsExceptionWhenNumOfPossibleOutcomeIsNegative()
			throws Exception {
		new ClassicalProbability(10, -2);
	}

	@Test(expected = IllegalArgumentException.class)
	public void ThrowsExceptionWhenNumOfEventsIsGreaterThanNumOfPossibleOutcome()
			throws Exception {
		new ClassicalProbability(10, 5);
	}
}
